package scanner;

public class Token {
    private String tokenText;
    private TokenType type;
    private int line, col;
    
    public Token(String yytext, TokenType type, int line, int col) {
        this.tokenText = yytext;
        this.type = type;
        this.line = line + 1; //JFlex fängt mit 0 an zu zählen
        this.col = col + 1;
    }
    
    public Token(TokenType type, String yytext, int line, int col) {
        this(yytext, type, line, col);
    }
    
    public Token(TokenType type, String yytext) {
        this(yytext, type, 0, 0);
    }
    
    public Token(String yytext, TokenType type) {
        this(yytext, type, 0, 0);
    }
    
    public String match() {
        return tokenText;
    }
    
    public TokenType type() {
        return type;
    }
    
    @Override
    public String toString() {
        if (type == TokenType.EOF)
            return "End of File";
        return tokenText;
		//return String.format("%-40s %-15s %3d:%2d", tokenText, type, line, col);
    }
    
    public int col() {
        return col;
    }
    
    public int line() {
        return line;
    }
	
    public boolean equals(String s) {
        if (type == TokenType.OPERATOR) 
            return tokenText.equalsIgnoreCase(s);
        return tokenText.equals(s);
    }
    
    public boolean equals(Token t) {
        return tokenText.equals(t.tokenText);
    }
    
    public boolean is(String s) {
        return type != TokenType.STRING && equals(s);
    }
}
